<?php
    $sql = "SELECT td_id,td_value FROM text_data WHERE td_id BETWEEN 10 AND 19 ORDER BY td_id";
    $result = $db->Execute($sql);
    
    $SITEURL = $iniVars['Locations']['siteurl'];
    $SITEPATH = $iniVars['Locations']['sitepath'];
    
    $course_input = '';
    
    while (!$result->EOF)
    {
        $data[$result->fields['td_id']] = $result->fields['td_value'];
        $result->MoveNext();
    }
    
    $result->Close();
    
    $i = 0;
    $course_img = '';
    if(file_exists($SITEPATH.$data['14'])){
        $i++;
        $course_img .= <<<sdl
            <li id="slideOrder_{$i}">
                <div class="courseImgList">
                    <img src="images/ajax-loader.gif" class="ajax_load_img delete_indicator"/>
                    <img src="{$SITEURL}{$data['14']}" class="courseImgThumb" />
                    <p>
                        <a href="javascript:void(0);" id="14" class="aLink deleteImg">Delete</a>
                    </p>
                </div>
            </li>
sdl;
    }else{
        $course_input .= '<p><input type="file" name="img14" /></p>';
    }
    
    if(file_exists($SITEPATH.$data['15'])){
        $i++;
        $course_img .= <<<sdl
            <li id="slideOrder_{$i}">
                <div class="courseImgList">
                    <img src="images/ajax-loader.gif" class="ajax_load_img delete_indicator"/>
                    <img src="{$SITEURL}{$data['15']}" class="courseImgThumb" />
                    <p>
                        <a href="javascript:void(0);" id="15" class="aLink deleteImg">Delete</a>
                    </p>
                </div>
            </li>
sdl;
    }else{
        $course_input .= '<p><input type="file" name="img15" /></p>';
    }
?>

<script type="text/javascript">
    $(document).ready(function(){
        
        var inputEle = <?php echo $i; ?>;
        if(inputEle<2)
        {
            $('.submitImgBt').css('display','block');
        }
        
        $("#tabs").tabs();
        
        $('.submitTopMsgBt').click(function(){
            $('.top_msg_submit_indicator').css('display','inline');
            var data = $("#rsTopMsgFrm").serialize();
            $.post('function/recruitmentServices.php',data,function(data){
                $('.top_msg_submit_indicator').css('display','none');
                if(trim(data)=='success')
                {
                    $("#top_msg_success_msg").html('บันทึกข้อมูลเรียบร้อยแล้ว');
                    $("#top_msg_success_msg").show('highlight',3000,function(){
                        $("#top_msg_success_msg").hide('highlight',3000);
                    });
                }
                else
                {
                    $("#top_msg_error_msg").html('ไม่สามารถบันทีกข้อมูลได้ กรุณาลองใหม่อีกครั้ง');
                    $("#top_msg_error_msg").html(data);
                    $("#top_msg_error_msg").show('highlight',3000,function(){
                        $("#top_msg_error_msg").hide('highlight',3000);
                    });
                }
            });
        });
        
        $('.submitImgDescBt').click(function(){
            $('.img_desc_submit_indicator').css('display','inline');
            var data = $("#rsImgDescFrm").serialize();
            $.post('function/recruitmentServices.php',data,function(data){
                $('.img_desc_submit_indicator').css('display','none');
                if(trim(data)=='success')
                {
                    $("#img_desc_success_msg").html('บันทึกข้อมูลเรียบร้อยแล้ว');
                    $("#img_desc_success_msg").show('highlight',3000,function(){
                        $("#img_desc_success_msg").hide('highlight',3000);
                    });
                }
                else
                {
                    $("#img_desc_error_msg").html('ไม่สามารถบันทีกข้อมูลได้ กรุณาลองใหม่อีกครั้ง');
                    $("#img_desc_error_msg").html(data);
                    $("#img_desc_error_msg").show('highlight',3000,function(){
                        $("#img_desc_error_msg").hide('highlight',3000);
                    });
                }
            });
        });
        
        $('.submitImgBt').click(function(){
            $("#img_success_msg").css('display','none');
            $("#img_error_msg").css('display','none');
            $('.img_submit_indicator').css('display','inline');
            $('#rsImgFrm').attr('method','post');
            $('#rsImgFrm').attr('target','ajaxIfrm');
            $('#rsImgFrm').submit();
        });
        
        $(".deleteImg").click(function(){
            if(confirm('Delete image?'))
            {
                var thisLi = $(this);
                thisLi.parents(".courseImgList").find('.delete_indicator').css('display','inline');
                var data = 'action=deleteImg&rsImgId=' + thisLi.attr('id');
                $.post('function/recruitmentServicesImg.php',data,function(data){
                    $('.delete_indicator').css('display','none');
                    if(trim(data)=='success')
                    {
                        thisLi.parents("li").remove();
                        $('.rsImgInput').append('<p style="margin-bottom:10px;"><input type="file" name="img'+thisLi.attr('id')+'" /></p>');
                        $('.submitImgBt').css('display','block');
                        $("#img_success_msg").html('ลบรูปเรียบร้อยแล้ว');
                        $("#img_success_msg").show('highlight',3000,function(){
                            $("#img_success_msg").hide('highlight',3000);
                        });
                    }
                    else
                    {
                        $("#img_error_msg").html('ไม่สามารถลบรูปได้ กรุณาลองใหม่อีกครั้ง');
                        $("#img_error_msg").html(data);
                        $("#img_error_msg").show('highlight',3000,function(){
                            $("#img_error_msg").hide('highlight',3000);
                        });
                    }
                });
            }
        });
        
    });
</script>

<h3 class="pageTitle">จัดการหน้า บริการจัดหาบุคลากร</h3>

<div id="tabs" class="courseEdit">
    
    <ul>
        <li id="car_"><a href="#tabs-1" title="Add files">Message</a></li>
        <li id="car_"><a href="#tabs-2" title="Add files">Images</a></li>
        <li id="car_"><a href="#tabs-3" title="Add files">Images description</a></li>
    </ul>
    <div id="tabs-1" class="rsTopMsgFrm">
        <form name="rsTopMsgFrm" id="rsTopMsgFrm">
            <p>
                <label>Message Thai :</label>
                <textarea name="msgTh" cols="50" rows="2" class="styled_textarea wysiwyg"><?php echo $data['10']; ?></textarea>
            </p>
            <p>
                <label>Message English :</label>
                <textarea name="msgEn" cols="50" rows="2" class="styled_textarea wysiwyg"><?php echo $data['11']; ?></textarea>
            </p>
            <p>
                <label>Message Japanese :</label>
                <textarea name="msgJp" cols="50" rows="2" class="styled_textarea wysiwyg"><?php echo $data['12']; ?></textarea>
            </p>
            <p>
                <label>Message chinese :</label>
                <textarea name="msgCh" cols="50" rows="2" class="styled_textarea wysiwyg"><?php echo $data['13']; ?></textarea>
            </p>
            <input type="hidden" name="action" value="topMsg" />
            <input type="button" class="button submitTopMsgBt" value="Save" />
            &nbsp;<img src="images/ajax-loader.gif" class="ajax_load_img top_msg_submit_indicator"/>
        </form>
        <div class="fail canhide png_bg ajax_msg" id="top_msg_error_msg"></div>
        <div class="success canhide ajax_msg" id="top_msg_success_msg"><p></p></div>
    </div>
    
    <div id="tabs-2" class="rsImgFrm">
        <form name="rsImgFrm" id="rsImgFrm" action='function/recruitmentServicesImg.php' enctype='multipart/form-data'>
            <ul class="courseImgOrderlist" id="courseImgList">
                <?php echo $course_img; ?>
            </ul>
            <div class="clear"></div>
            <div class="rsImgInput">
                <?php echo $course_input; ?>
            </div>
            <input type="button" class="button submitImgBt hiddenEle" value="Submit" />
            <input type="hidden" name="action" value="uploadImg" />
            &nbsp;<img src="images/ajax-loader.gif" class="ajax_load_img img_submit_indicator"/>
        </form>
        <div class="information canhide png_bg">จำนวนรูปภาพ 2 รูป และขนาดรูปภาพแนะนำคือ 285x175 pixel</div>
        <div class="fail canhide png_bg ajax_msg" id="img_error_msg"></div>
        <div class="success canhide ajax_msg" id="img_success_msg"><p></p></div>
        <iframe name="ajaxIfrm" class="ajaxIfrm" ></iframe>
    </div>
    
     <div id="tabs-3" class="rsImgDescFrm">
         <form name="rsImgDescFrm" id="rsImgDescFrm">
            <p>
                <label>Thai :</label>
                <textarea name="imgDescTh" cols="50" rows="3" class="styled_textarea wysiwyg"><?php echo $data['16']; ?></textarea>
            </p>
            <p>
                <label>English :</label>
                <textarea name="imgDescEn" cols="50" rows="3" class="styled_textarea wysiwyg"><?php echo $data['17']; ?></textarea>
            </p>
            <p>
                <label>Japanese :</label>
                <textarea name="imgDescJp" cols="50" rows="3" class="styled_textarea wysiwyg"><?php echo $data['18']; ?></textarea>
            </p>
            <p>
                <label>chinese :</label>
                <textarea name="imgDescCh" cols="50" rows="3" class="styled_textarea wysiwyg"><?php echo $data['19']; ?></textarea>
            </p>
            <input type="hidden" name="action" value="imgDesc" />
            <input type="button" class="button submitImgDescBt" value="Save" />
            &nbsp;<img src="images/ajax-loader.gif" class="ajax_load_img img_desc_submit_indicator"/>
        </form>
        <div class="information canhide png_bg ajax_msg"></div>
        <div class="fail canhide png_bg ajax_msg" id="img_desc_error_msg"></div>
        <div class="success canhide ajax_msg" id="img_desc_success_msg"><p></p></div>
    </div>
</div>